import socket

sever_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("hostname:", socket.gethostname())
sever_socket.bind(('0.0.0.0', 9999))

sever_socket.listen(1)  # 限制最多一个客户端
client_socket, addr = sever_socket.accept()  # 等待客户端连接
print("Got connection from:", addr)  # 输出客户端ip
# 循环输入指令
while True:
    command: str = input("请输入你要执行的指令（1：开灯，0：关灯，close:中断连接）").strip()
    client_socket.send(command.encode())  # 发送指令
    if command == "close":
        break

client_socket.close()  # 关闭客户端连接
sever_socket.close()  # 关闭服务端连接
